package com.v2future.sjt.collegecheckingattendance.fruit;

import android.widget.GridView;
import android.widget.TextView;

import com.v2future.sjt.collegecheckingattendance.MainActivity;
import com.v2future.sjt.collegecheckingattendance.R;
import com.v2future.sjt.collegecheckingattendance.event.adapter.ReleaseEventImgGridAdapter;
import com.v2future.sjt.collegecheckingattendance.event.bean.ReleaseEventImageBean;
import com.v2future.sjt.collegecheckingattendance.fruit.bean.ConditionBean;
import com.v2future.sjt.collegecheckingattendance.fruit.bean.ConditionTypeBean;
import com.v2future.sjt.collegecheckingattendance.utils.IntentKey;
import com.v2future.sjt.collegecheckingattendance.utils.WidgetUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 成长详情
 *
 * @author shijianting
 * @time 2016/5/12 19:20
 */
public class FruitDetailActivity extends MainActivity {

    @Bind(R.id.tv_titletext)
    TextView tvTitletext;
    @Bind(R.id.tv_time)
    TextView tvTime;
    @Bind(R.id.tv_addr)
    TextView tvAddr;
    @Bind(R.id.tv_content)
    TextView tvContent;
    @Bind(R.id.gv_images)
    GridView gvImages;

    /**
     * 传入的成长详情
     */
    private ConditionBean conditionBean;

    /**
     * 成长类型
     */
    private ConditionTypeBean conditionTypeBean;

    /**
     * 适配器装载图片的列表
     */
    List<ReleaseEventImageBean> imageDataList;

    /**
     * 图片展示适配器
     */
    ReleaseEventImgGridAdapter adapter;

    @Override
    public void init() {
        conditionTypeBean = (ConditionTypeBean) getIntent().getSerializableExtra(IntentKey.FRUIT_TYPE);
        conditionBean = (ConditionBean) getIntent().getSerializableExtra(IntentKey.CONDITION);
    }

    @Override
    public void initView() {
        setContentView(R.layout.activity_fruit_detail);
        ButterKnife.bind(this);
        initTitleBack(null);
        setTitleText(conditionTypeBean.getConditonTypeName());
    }

    @Override
    public void initAfter() {
        WidgetUtil.setText(tvTitletext, conditionBean.getConditionTitle());
        WidgetUtil.setText(tvTime, conditionBean.getConditionDate());
        WidgetUtil.setText(tvAddr, conditionBean.getConditionArea());
        WidgetUtil.setText(tvContent, conditionBean.getConditionDesc());
        if (null != conditionBean.getImageUrl() && conditionBean.getImageUrl().size() > 0) {
            imageDataList = new ArrayList<>();
            for (int i=0;i<conditionBean.getImageUrl().size();i++) {
                ReleaseEventImageBean bean = new ReleaseEventImageBean();
                bean.setImageUrl(conditionBean.getImageUrl().get(i));
                imageDataList.add(bean);
            }
            adapter = new ReleaseEventImgGridAdapter(this, imageDataList);
            gvImages.setAdapter(adapter);
        }

    }

}
